import Vue from 'vue'
import VueRouter from 'vue-router'
import Main from '../views/Main.vue'
import Dept from '../views/Dept.vue'
import Staff from '../views/Staff.vue'
import StaffAttend from '../views/StaffAttend.vue'
import WorkArea from '../views/WorkArea.vue'
import Home from '../views/Home/HomePage.vue'
import OtherPage from '../views/Home/MonitorPage.vue'
import SystemHome from '../views/SystemHome/SystemPage.vue'
import StaffPage from '../views/Staff/StaffPage.vue'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'

Vue.use(VueRouter)

//1.创建路由组件
//2.将路由与组件进行映射
//3.创建router实例

const routes = [
    //主路由
    {
        path: '/',
        component: Main,
        //子路由
        children: [
            { path: 'Dept', component: Dept },
            { path: 'Home', component: Home },
            { path: 'OtherPage', component: OtherPage },
            { path: 'StaffPage', component: StaffPage },
            { path: 'SystemHome', component: SystemHome },
            { path: 'Staff', component: Staff },
            { path: 'StaffAttend', component: StaffAttend },
            { path: 'WorkArea', component: WorkArea },
            { path: 'Login', component: Login },
            { path: 'Register', component: Register }
        ]
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes // (缩写) 相当于 routes: routes
})

export default router
//解决vue-router重复路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}
